(function(){
    /*
    * <div class="formGroup row">
     <label class="col-sm-2 formLabel">姓名</label>
     <div class="col-sm-10">
     <input type="text" placeholder="Email" />
     </div>
     </div>
     <div class="formGroup row">
     <label class="col-sm-2 formLabel">类目类目</label>
     <div class="col-sm-10">
     <label class="radio-inline">
     <input type="radio" name="inlineRadioOptions" value="option1"> 1
     </label>
     </div>
     </div>
     <div class="formGroup row">
     <label class="col-sm-2 formLabel">类目类目</label>
     <div class="col-sm-10">
     <label class="checkbox-inline">
     <input type="checkbox" name="inlineRadioOptions" value="option1"><span>1</span>
     </label>
     <label class="checkbox-inline">
     <input type="checkbox" name="inlineRadioOptions" value="option1"> 1
     </label>
     <label class="checkbox-inline">
     <input type="checkbox" name="inlineRadioOptions" value="option1"> 1
     </label>
     </div>
     </div>
     <div class="formGroup row">
     <label class="col-sm-2 formLabel">类目类目</label>
     <div class="imageContent col-sm-9">
     <div class="uploadedImage">
     <img class="uploadImage" src="./img/add_image.png" alt="上传图片" />
     </div>
     <div class="uploadedImage">
     <img class="image" src="./img/add_image.png" alt="上传图片" />
     <img class="imageDeleteBtn" src="./img/image_delete.png" alt="删除图片" />
     </div>
     <div class="uploadedImage">
     <img class="image" src="./img/add_image.png" alt="上传图片" />
     <img class="imageDeleteBtn" src="./img/image_delete.png" alt="删除图片" />
     </div>
     <div class="uploadedImage">
     <img class="image" src="./img/add_image.png" alt="上传图片" />
     <img class="imageDeleteBtn" src="./img/image_delete.png" alt="删除图片" />
     </div>
     </div>
     </div>
     <div class="formGroup row">
     <label class="col-sm-2 formLabel">类目类目</label>
     <div class="col-sm-10">
     <div class="uploadedImage">
     <img class="uploadImage" src="./img/add_image.png" alt="上传图片" />
     </div>
     <div class="uploadedImage">
     <img class="image" src="./img/add_image.png" alt="上传图片" />
     <img class="imageDeleteBtn" src="./img/image_delete.png" alt="删除图片" />
     </div>
     </div>
     </div>
     <div class="formGroup row">
     <label class="col-sm-2 formLabel">类目类目</label>
     <div class="col-sm-10">
     <textarea></textarea>
     </div>
     </div>
     <div class="formGroup" style="height: 400px;">
     <label class="col-sm-2 formLabel">类目类目</label>
     <div class="col-sm-12">
     <div class="wangEditor" style="height:300px;max-height:300px;"></div>
     </div>
     </div>
    * */
    function Vender(){
        var checkObj = function(value){
            if(value.constructor == Object){
                return true;
            }else{
                return false;
            }
        };
        var init = function(obj){
            var final = {};
            if(checkObj(obj)){
                final = {
                    labelName : obj.labelName || '',
                    className : obj.className || '',
                    placeHolder : obj.placeHolder || '',
                    value : obj.value || '',
                    optionObj: obj.optionObj || '',
                    allowChange : obj.allowChange
                };
            }else{
                final = {
                    labelName : '',
                    className : '',
                    placeHolder : '',
                    value : '',
                    optionObj: '',
                    allowChange : true
                };
            }
            return final;
        };
        this.createInput = function(obj){
            var initObj = init(obj);

            var div = document.createElement('div');
            div.setAttribute('class','formGroup row');
            var label = document.createElement('label');
            label.setAttribute('class','col-sm-2 formLabel');
            label.innerText = initObj.labelName;
            var div_col = document.createElement('div');
            div_col.setAttribute('class','col-sm-10');
            var input = document.createElement('input');
            input.setAttribute('class',initObj.className);
            input.setAttribute('type','text');
            input.setAttribute('placeholder',initObj.placeHolder);
            if(initObj.value){
                input.value = initObj.value;
            }
            if(!initObj.allowChange){
                input.setAttribute('disabled','disabled');
            }

            div.appendChild(label);
            div_col.appendChild(input);
            div.appendChild(div_col);
            return div;
        };
        this.createSelect = function(obj){
            var initObj = init(obj);
            var div = document.createElement('div');
            div.setAttribute('class','formGroup row');
            var label = document.createElement('label');
            label.setAttribute('class','col-sm-2 formLabel');
            label.innerText = initObj.labelName;
            var div_col = document.createElement('div');
            div_col.setAttribute('class','col-sm-10');

            for(x in initObj.optionObj){
                var label_radio = document.createElement('label');
                label_radio.setAttribute('class','radio-inline');
                var input = document.createElement('input');
                input.setAttribute('type','radio');
                input.setAttribute('name',initObj.className);
                input.setAttribute('value',x);
                var span = document.createElement('span');
                span.innerText = initObj.optionObj[x];
                if(x == initObj.value){
                    input.setAttribute('checked','checked');
                }
                label_radio.appendChild(input);
                label_radio.appendChild(span);
                div_col.appendChild(label_radio);
            }

            div.appendChild(label);
            div.appendChild(div_col);
            return div;
        };
        this.createCheckBox = function(obj){
            var initObj = init(obj);

            var div = document.createElement('div');
            div.setAttribute('class','formGroup row');
            var label = document.createElement('label');
            label.setAttribute('class','col-sm-2 formLabel');
            label.innerText = initObj.labelName;
            var div_col = document.createElement('div');
            div_col.setAttribute('class','col-sm-10');

            for(var x in initObj.optionObj){
                var label_checkbox = document.createElement('label');
                label_checkbox.setAttribute('class','checkbox-inline');
                var input = document.createElement('input');
                for(var i=0;i<initObj.value.length;i++){
                    if(initObj.optionObj[x] == initObj.value[i]){
                        input.setAttribute('checked','checked');
                        break;
                    }
                }
                input.setAttribute('type','checkbox');
                input.setAttribute('name',initObj.className);
                input.setAttribute('value',x);
                var span = document.createElement('span');
                span.innerText = initObj.optionObj[x];
                label_checkbox.appendChild(input);
                label_checkbox.appendChild(span);
                div_col.appendChild(label_checkbox);
            }

            div.appendChild(label);
            div.appendChild(div_col);
            return div;
        };
        this.createImage = function(obj){
            var initObj = init(obj);
            var div = document.createElement('div');
            div.setAttribute('class','formGroup row');
            var label = document.createElement('label');
            label.setAttribute('class','col-sm-2 formLabel');
            label.innerText = initObj.labelName;
            var div_col = document.createElement('div');
            div_col.setAttribute('class','col-sm-10 '+initObj.className+'_OuterContainer');
            var div_upload_img = document.createElement('div');
            div_upload_img.setAttribute('class','uploadedImage');
            var upload_img = document.createElement('img');
            upload_img.setAttribute('class','uploadImage');
            upload_img.setAttribute('src','./img/add_image.png');
            upload_img.setAttribute('alt','上传图片');

            $(upload_img).on('click',function(){
                var outerClass = $(this).parent('.uploadedImage').parent('div').attr('class');
                window.localStorage.setItem('outerClass',outerClass.split(' ')[outerClass.split(' ').length-1]);
                $('#hiddenUploadInput').click();
            });

            div_upload_img.appendChild(upload_img);
            div_col.appendChild(div_upload_img);
            if(initObj.value){
                var div_uploaded_img = document.createElement('div');
                div_uploaded_img.setAttribute('class','uploadedImage');
                var uploaded_img = document.createElement('img');
                uploaded_img.setAttribute('class',initObj.className);
                uploaded_img.setAttribute('src',initObj.value);
                var delete_img = document.createElement('img');
                delete_img.setAttribute('class','imageDeleteBtn');
                delete_img.setAttribute('src','./img/image_delete.png');
                delete_img.setAttribute('alt','删除图片');

                $(delete_img).on('click',function(){
                    $(this).parent('.uploadedImage').remove();
                });

                div_uploaded_img.appendChild(uploaded_img);
                div_uploaded_img.appendChild(delete_img);
                div_col.appendChild(div_uploaded_img);
            }
            div.appendChild(label);
            div.appendChild(div_col);

            return div;
        };
        this.createMoreImage = function(obj){
            var initObj = init(obj);

            var div = document.createElement('div');
            div.setAttribute('class','formGroup row');
            var label = document.createElement('label');
            label.setAttribute('class','col-sm-2 formLabel');
            label.innerText = initObj.labelName;

            var div_col = document.createElement('div');
            div_col.setAttribute('class','imageContent col-sm-9 '+initObj.className+'_OuterContainer');
            var div_upload_img = document.createElement('div');
            div_upload_img.setAttribute('class','uploadedImage');
            var upload_img = document.createElement('img');
            upload_img.setAttribute('class','uploadImage');
            upload_img.setAttribute('src','./img/add_image.png');
            upload_img.setAttribute('alt','上传图片');

            $(upload_img).on('click',function(){
                var outerClass = $(this).parent('.uploadedImage').parent('div').attr('class');
                window.localStorage.setItem('outerClass',outerClass.split(' ')[outerClass.split(' ').length-1]);
                $('#hiddenUploadInput').click();
            });

            div_upload_img.appendChild(upload_img);
            div_col.appendChild(div_upload_img);
            if(initObj.value){
                for(var i=0;i<initObj.value.length;i++){
                    var div_uploaded_img = document.createElement('div');
                    div_uploaded_img.setAttribute('class','uploadedImage');
                    var uploaded_img = document.createElement('img');
                    uploaded_img.setAttribute('class',initObj.className);
                    uploaded_img.setAttribute('src',initObj.value[i]);
                    var delete_img = document.createElement('img');
                    delete_img.setAttribute('class','imageDeleteBtn');
                    delete_img.setAttribute('src','./img/image_delete.png');
                    delete_img.setAttribute('alt','删除图片');

                    $(delete_img).on('click',function(){
                        $(this).parent('.uploadedImage').remove();
                    });

                    div_uploaded_img.appendChild(uploaded_img);
                    div_uploaded_img.appendChild(delete_img);
                    div_col.appendChild(div_uploaded_img);
                }
            }
            div.appendChild(label);
            div.appendChild(div_col);

            return div;
        };
        this.createTextarea = function(obj){
            var initObj = init(obj);

            var div = document.createElement('div');
            div.setAttribute('class','formGroup row');
            div.setAttribute('style','height: 400px;');
            var label = document.createElement('label');
            label.setAttribute('class','col-sm-2 formLabel');
            label.innerText = initObj.labelName;
            var div_col = document.createElement('div');
            div_col.setAttribute('class','col-sm-10');
            var textarea = document.createElement('textarea');

            div.appendChild(label);
            div_col.appendChild(textarea);
            div.appendChild(div_col);

            return div;
        };
        this.createRichTextarea = function(obj){
            var initObj = init(obj);

            var div = document.createElement('div');
            div.setAttribute('class','formGroup');
            div.setAttribute('style','height: 400px;');
            var label = document.createElement('label');
            label.setAttribute('class','col-sm-2 formLabel');
            label.innerText = initObj.labelName;
            var div_col = document.createElement('div');
            div_col.setAttribute('class','col-sm-12');
            var script = document.createElement('script');
            script.setAttribute('id',initObj.className);
            //var editor = document.createElement('div');
            //editor.setAttribute('class',initObj.className);
            //editor.setAttribute('style','height:300px;max-height:300px;');
            //editor.innerHTML = initObj.value;
            div.appendChild(label);
            div_col.appendChild(script);
            div.appendChild(div_col);

            return div;
        }
    }

    window.Vender = new Vender();
})();